<?php if (!defined('insite')) die("no access"); 
unset($ntime);
$ntime =  @filemtime("_dat/cach/top_strongest");
require "opt.php";

if(!$ntime || (time()-$ntime>$config["tstrongest"]))
{
		if ($config["show_adm"]==0) $show_gm="CtlCode !=32 and";
		else $show_gm="";
		$resulttop5 = $db->query("SELECT TOP 5 Name,".$config["res_colum"].",cLevel, AccountID, Class,gr_res from Character WHERE ".$show_gm." CtlCode != 1 and CtlCode != 17  ".$config["str_sort"]);
		$count = $db->numrows($resulttop5);
	ob_start();	

if ($config["top_type"]==1)
{
for($i=0;$i < $count;$i++)
{
	$rowtop5 = $db->fetchrow($resulttop5);
	$oinfoc = $db->fetchrow($db->query("SELECT MEMB_STAT.ConnectStat FROM AccountCharacter, MEMB_STAT WHERE AccountCharacter.GameIDC='$rowtop5[0]' and MEMB_STAT.memb___id='$rowtop5[3]'"));
	$respg = $db->query("SELECT G_Name FROM GuildMember WHERE Name='$rowtop5[0]'");
	$pg1 = $db->numrows($respg);
	if ($pg1>0) 
	{$pg =$db->fetchrow($respg);}
	else $pg[0]=0;	
	$rowtop5[4] = classname($rowtop5[4]);
	if (empty($pg[0])||$pg[0]==0)
	{
		$chkgm = $db->fetchrow($db->query("SELECT Name,G_Name FROM GuildMember WHERE Name='$rowtop5[0]'"));
		if ($chkgm) $pg[0]=$chkgm[1];
		else $pg[0]="none";
	}
	if ($oinfoc[0]==0)
	{
		$oinfo1 = $db->fetchrow($db->query("SELECT DisConnectTM FROM MEMB_STAT WHERE memb___id='$rowtop5[3]'"));
		$stats = "<span style=color:#FF0505;font-weight:bold;font-size:12px;>Offline</span> ";
	}
	else if ($oinfoc[0]==1)
	{
		$oinfo1 = $db->fetchrow($db->query("SELECT ConnectTM FROM MEMB_STAT WHERE memb___id='$rowtop5[3]'"));	
		$stats="<span style=color:#04C200;font-weight:bold;font-size:12px;>Online</span> ";
	}
	if ($config["greset"]==1 && $config["greset_st"]==1)
	{
		$gr_star="&nbsp;";
		while ($rowtop5[5]>0)
		{
			$gr_star.="<img src=\"imgs/gres.gif\"  border=\"0\" />";
			$rowtop5[5]--;
		}
	}else if ($config["greset"]==1 && $config["greset_st"]==0)
	{
		$gr_star=" <br>Grand Reset:".$rowtop5[5];
	}
	$oinfo = "
	".sreongest_guild." <i> ".$pg[0]."</i><br>
	".sreongest_class." <i>".$rowtop5[4]."</i><br>
	".sreongest_status." <i>".$stats."<br>"; if($oinfo1[0]!=NULL) $oinfo.="".sreongest_pr." ".$oinfo1[0]." </i>";

	echo "<div align='center' style='height:17px;'  title='".$oinfo." <br> Level: ".$rowtop5[2]."<br>Reset: ".$rowtop5[1].$gr_star."'><a href='".$config["siteaddress"]."?p=search&caracter=".$rowtop5[0]."'>".$rowtop5[0]."</a></div>";

}
}
elseif ($config["top_type"]==2)
{
	$class_list = explode(",", $config["stron_sh"]);
	$st_show="";
	foreach ($class_list as $n=>$v)
	{
		$st_show.=q_chr_top($v);
	}
	echo $st_show;
}
elseif ($config["top_type"]==3) //hall of flame (FROM DEW, thx deathless) 
{
 
 $hide_nick_list = explode(',', $hidenicks);
 if (strlen($hide_nick_list[0])>2)
 {
  foreach($hide_nick_list as $id=>$val)
  {
    $nick_hide.= "and Name != '".$val."' ";
  }
 }
 else
  $nick_hide="";
 
 
 $BEST_PLAYER = $db->fetchrow($db->query("SELECT TOP 1 name,clevel,".$config["res_colum"] ." FROM Character WHERE (ctlcode != 32 AND ctlcode != 8) $nick_hide order by gr_res desc, ".$config["res_colum"] ." desc, clevel desc"));
 $BEST_DK = $db->fetchrow($db->query("SELECT TOP 1 name,clevel,".$config["res_colum"] ." FROM Character WHERE (Class = 16 OR Class = 17 OR Class = 18 OR Class = 19) AND (ctlcode != 32 AND ctlcode != 8) $nick_hide order by gr_res desc, ".$config["res_colum"] ." desc, clevel desc"));
 $BEST_DW = $db->fetchrow($db->query("SELECT TOP 1 name,clevel,".$config["res_colum"] ." FROM Character WHERE (Class = 0 OR Class = 1 OR Class = 2 OR Class = 3) AND (ctlcode != 32 AND ctlcode != 8) $nick_hide order by gr_res desc, ".$config["res_colum"] ." desc, clevel desc"));
 $BEST_ELF = $db->fetchrow($db->query("SELECT TOP 1 name,clevel,".$config["res_colum"] ." FROM Character WHERE (Class = 32 OR Class = 33 OR Class = 34 OR Class = 35) AND (ctlcode != 32 AND ctlcode != 8) $nick_hide order by gr_res desc, ".$config["res_colum"] ." desc, clevel desc"));
 $BEST_MG = $db->fetchrow($db->query("SELECT TOP 1 name,clevel,".$config["res_colum"] ." FROM Character WHERE (Class = 48 OR Class = 49 OR Class = 50) AND (ctlcode != 32 AND ctlcode != 8) $nick_hide order by gr_res desc, ".$config["res_colum"] ." desc, clevel desc"));
 $BEST_DL = $db->fetchrow($db->query("SELECT TOP 1 name,clevel,".$config["res_colum"] ." FROM Character WHERE (Class = 64 OR Class = 65 OR Class = 66) AND (ctlcode != 32 AND ctlcode != 8) $nick_hide order by gr_res desc, ".$config["res_colum"] ." desc, clevel desc"));
 $BEST_SUM = $db->fetchrow($db->query("SELECT TOP 1 name,clevel,".$config["res_colum"] ." FROM Character WHERE (Class = 80 OR Class = 81 OR Class = 82 OR Class = 83) AND (ctlcode != 32 AND ctlcode != 8) $nick_hide order by gr_res desc, ".$config["res_colum"] ." desc, clevel desc"));
 $BEST_ZEN = $db->fetchrow($db->query("SELECT TOP 1 name,clevel,".$config["res_colum"] .",money FROM Character WHERE (ctlcode != 32 AND ctlcode != 8) $nick_hide order by money desc"));
 $BEST_GUILD = $db->fetchrow($db->query("SELECT TOP 1 G_Name,G_Score,G_Master FROM Guild order by G_Score desc"));
 
 $cs_info = know_csstate();
 $cs = "<a title=\"Start: ".$cs_info[2]."<br>End: ".$cs_info[3]."<br>Period: ".$cs_info[1]."\" href='".$config["siteaddress"]."/p=cs'>".$cs_info[0]."</a>";


	if (strlen($BEST_PLAYER[0])>1) echo "<div style=\"padding-left:3px;\" align=\"left\"><span class=\"yarr\">Strongest:</span> <a title='Level: ".$BEST_PLAYER[1]."<br>Resets: ".$BEST_PLAYER[2]."'>".$BEST_PLAYER[0]."</a></div>";
	if (strlen($BEST_DK[0])>1) echo "<div style=\"padding-left:7px;\" align=\"left\"><span class=\"yarr\">&raquo; Strongest BK</span> <a title ='Level: ".$BEST_DK[1]."<br>Resets: ".$BEST_DK[2]."'>".$BEST_DK[0]."</a></div>";
	if (strlen($BEST_DW[0])>1) echo "<div style=\"padding-left:7px;\" align=\"left\"><span class=\"yarr\">&raquo; Strongest SM:</span> <a title ='Level: ".$BEST_DW[1]."<br>Resets: ".$BEST_DW[2]."'>".$BEST_DW[0]."</a></div>";
	if (strlen($BEST_ELF[0])>1) echo "<div style=\"padding-left:7px;\" align=\"left\"><span class=\"yarr\">&raquo; Strongest Elf:</span> <a title = 'Level: ".$BEST_ELF[1]."<br>Resets: ".$BEST_ELF[2]."'>".$BEST_ELF[0]."</a></div>";
	if (strlen($BEST_MG[0])>1) echo "<div style=\"padding-left:7px;\" align=\"left\"><span class=\"yarr\">&raquo; Strongest MG:</span> <a title = 'Level: ".$BEST_MG[1]."<br>Resets: ".$BEST_MG[2]."'>".$BEST_MG[0]."</a></div>";
	if (strlen($BEST_DL[0])>1) echo "<div style=\"padding-left:7px;\" align=\"left\"><span class=\"yarr\">&raquo; Strongest DL:</span> <a title = 'Level: ".$BEST_DL[1]."<br>Resets: ".$BEST_DL[2]."'>".$BEST_DL[0]."</a></div>";
	if (strlen($BEST_SUM[0])>1) echo "<div style=\"padding-left:5px;\" align=\"left\"><span class=\"yarr\">&raquo; Strongest SUM:</span> <a title ='Level: ".$BEST_SUM[1]."<br>Resets: ".$BEST_SUM[2]."'>".$BEST_SUM[0]."</a></div>";
	
	echo "	
		<div style=\"padding-left:3px;\" align=\"left\"><span class=\"yarr\">".strtop_reach.":</span> <a title ='Level: ".$BEST_ZEN[1]."<br>Resets: ".$BEST_ZEN[2]."<br>Money: ".print_price($BEST_ZEN[3])." Zen'>".$BEST_ZEN[0]."</a></div>
		<div style=\"padding-left:3px;\" align=\"left\"><span class=\"yarr\">".strtop_g.":</span> <a title ='Guild Master: ".$BEST_GUILD[2]."<br>Points: ".$BEST_GUILD[1]."'>".$BEST_GUILD[0]."</a></div> 
		<div style=\"padding-left:3px;\" align=\"left\"><span class=\"yarr\"><a>Castle Siege</a>:</span> ".$cs."</div>";
}
else echo "error: in top_type!";
?><div align='center' style='height:10px;'>&nbsp;</div>
<!--<?=($config["tstrongest"]/60)?>-->			
<?		
$content = ob_get_contents();
write_catch ("_dat/cach/top_strongest",$content);
ob_end_clean();	  echo $content;
			
} else require '_dat/cach/top_strongest';
?>
